package logic

import (
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelNumLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelNumLogic {
	return &CartDelNumLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 减少购物车商品数量
func (l *CartDelNumLogic) CartDelNum(in *homepage.CartDelNumRequest) (*homepage.CartDelNumResponse, error) {
	err := dao.CartDecreaseGoodsNum(int(in.UserId), int(in.GoodsId), int(in.SkuId))
	if err != nil {
		pkg.Error("减少数量失败", zap.Error(err))
		return nil, err
	}

	return &homepage.CartDelNumResponse{Msg: "减少成功"}, nil
}
